//
//  FYDesc.m
//  ThePainter
//
//  Created by Sean on 15/8/20.
//  Copyright (c) 2015年 FeiYu. All rights reserved.
//

#import "FYDesc.h"

@interface FYDesc()

@property (nonatomic)NSString *string;

@property (nonatomic)CGFloat fontSize;

@property (nonatomic)UIColor *color;

@property (nonatomic)CGFloat width;

- (void)initView;

@end

@implementation FYDesc

- (id)initWithString:(NSString*)string fontSize:(CGFloat)fontSize color:(UIColor*)color width:(CGFloat)width {
    if (self=[super init]) {
        self.string = string;
        self.fontSize = fontSize;
        self.color = color;
        self.width = width;
        [self initView];
    }
    return self;
}

- (void)initView {
    //宽度不变，根据字的多少计算label的高度
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:self.fontSize]};
    CGRect labDescRect = [self.string boundingRectWithSize:CGSizeMake(self.width, CGFLOAT_MAX)
                                                               options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                                            attributes:attributes
                                                               context:nil];
    self.frame = CGRectMake(0, 0, labDescRect.size.width, labDescRect.size.height);
    self.backgroundColor = [UIColor clearColor];
    self.text = self.string;
    self.textAlignment = NSTextAlignmentLeft;
    self.font = [UIFont systemFontOfSize:self.fontSize];
    self.textColor = self.color;
    //不做行数限制
    self.numberOfLines = 0;
}

@end
